package com.wuyou.simple;

import java.util.Arrays;
import java.util.Collections;

/**
 * @Description 27. 移除元素
 * @Author yh.zhang
 * @Date 2023/11/22 9:48
 */
public class RemoveElement {


    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        int val = 3;
        System.out.println(solution_1(nums, val));
    }
    public static int solution_1(int[] nums, int val){
        int ans = nums.length;

        for (int i = 0; i < ans; i++) {
            if (nums[i] == val) {
                nums[i] = 0;
                ans --;
                int temp = nums[ans];
                nums[i] = temp;
                nums[ans] = 0;
                i--;
            }
        }
        return ans;
    }
}
